home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 1 / ACE CD 1.iso / files / utils / acroarex.dms / in.adf / Public_Domain / PD_STUFF.lha / RexxIntuition / Scripts / journal.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1992-05-30  |  5.2 KB  |  182 lines

  1. /* Modified excerpt of Journal to demo using RexxIntuition library */
  2. /* Set your editor's TAB width to 3 */
  3.  
  4. /* ----- Get today's date (using CLI Date command) into our 3 variables ---- */
  5. address command('date to ram:date')
  6. open('dat','ram:date','R')
  7. seek('dat',0,'B')
  8. spec = readln('dat')
  9. parse var spec day date time
  10. close('dat')
  11. spec = ' Journal entry for 'date
  12. path = date
  13. trace results
  14.  
  15. /* ----- Open the screen/window (defaults) for Journal, attach menu ---- */
  16. screen = rxi_GetScreen(spec,,,,,,2)
  17. window = rxi_GetWindow(spec,screen,,,,,,64+256+512+8,4096+2048+256)
  18. menu = rxi_AddMenu(window,'Project',1,)
  19. item = rxi_AddItem(menu,'Make Entry  ',4,,,'M',window)
  20. item = rxi_AddItem(menu,'Read Entry  ',4,,,'R',window)
  21. item = rxi_AddItem(menu,'Delete Entry',4,,,'D',window)
  22. item = rxi_AddItem(menu,'New         ',4,,,'N',window)
  23. item = rxi_AddItem(menu,'Quit        ',4,,128,'Q',window)
  24.  
  25. /* ---- Add string gadgets for each line of the Journal (actually, a ---- */
  26. /* ---- text editor that can interact with an ARexx script such as ---- */
  27. /* ---- dissidents disEd would be best (plug).        ---- */
  28.  
  29. err = rxi_SetDraw(window,0,0,0) /* So that string gadget borders are invisible */
  30. width = rxi_PEEK(window,8,1) /* Get window's width */
  31. numChars = (width-8)/8
  32. numLines = rxi_PEEK(window,10,1) /* Get window's height */
  33. numLines = ((numLines-10)/10)-1
  34. err = 0
  35. do i = 0 to numLines
  36.  yoffset = 10 + (10*i)
  37.  gadg = rxi_AddGadg(window,4,,,yoffset,width,10,1,i,2,numChars)
  38.  if err = 0 then do
  39.   gadglist = gadg /* Save the address of our first str gadget for later */
  40.   err = 1
  41.  end
  42. end
  43. err = rxi_SetDraw(window,1,0,1) /* reset to defaults */
  44.  
  45. /* ---- Get a ReqDef for file requester ---- */
  46. reqdef = rxi_GetReq()
  47.  
  48. /* ---- Do our IDCMP loop ---- */
  49. class = 1
  50. do while class > 0
  51.  spec = rxi_WaitMsg(window)
  52.  parse var spec class part1 part2 part3
  53.  if class = 2 then do
  54.   if part2 = 0 then do
  55.    call MakeEntry
  56.   end
  57.   if part2 = 1 then do
  58.    call ReadEntry
  59.   end
  60.   if part2 = 2 then do
  61.    call DeleteEntry
  62.   end
  63.   if part2 = 3 then do
  64.    call NewEntry
  65.   end
  66.  end
  67. end
  68.  
  69. /* ----- Close window and screen, and exit ----- */
  70. ending:
  71.  reqdef = rxi_EndReq(reqdef)
  72.  window = rxi_EndWindow(window)
  73.  screen = rxi_EndScreen(screen)
  74. exit 0
  75.  
  76. /* ------ Saves the contents of string gadgets into the Journal file ------- */
  77. MakeEntry:
  78.  /* Get journal filename */
  79.  path = rxi_ReqNW(reqDef,'Save Journal File:',8192,,'.JLE',date,,,window,-1,-1)
  80.  if path > '' then do
  81.   err = rxi_Peek(reqdef,4,0)
  82.   if err > 0 then do
  83.    /* See if the file exists, and if so, ask about appending */
  84.    err = rxi_Peek(reqdef,204,2)
  85.    if err > 0 then do
  86.     err = rxi_MsgThree(window,'The Journal File',path,'exists. Append it?')
  87.     if err = 0 then return('')
  88.     err = rxi_Title(window,reqdef,'Appending to existing entry...',)
  89.     open('jnl',path,'A')
  90.    end
  91.    if err = 0 then do
  92.     err = rxi_Title(window,reqdef,'Creating new entry...',)
  93.     open('jnl',date'.JLE','W')
  94.     /* Here, we should write out some heading to the file. I removed that */
  95.     close ('jnl')
  96.     open('jnl',date'.JLE','A')
  97.    end
  98.    call LineLoop
  99.    end
  100.   end
  101.  return('')
  102.  
  103. LineLoop:
  104.  do i = 0 to numLines
  105.   Entri = rxi_GInfo(window,i)
  106.   writeln('jnl',Entri)
  107.  end i
  108.  close('jnl')
  109.  err = rxi_Title(window,reqdef,'Saved OK',)
  110.  return('')
  111.  
  112. /* ---------- Reads the Journal file into the string gadgets ----------- */
  113. ReadEntry:
  114.  /* Get journal filename */
  115.  path = rxi_ReqNW(reqDef,'Read Journal File:',8192,,'.JLE',path,,,window,-1,-1)
  116.  if path > '' then do
  117.   err = rxi_Peek(reqdef,4,0)
  118.   if err > 0 then do
  119.    /* See if the file exists, and if so, load it into string gadgets */
  120.    err = rxi_Peek(reqdef,204,2)
  121.    if err > 0 then do
  122.     open('jnlR',path,'R')
  123.     err = rxi_Title(window,reqdef,' Reading journal... ',)
  124.     seek('jnlR',0,'B')
  125.     Entri=readln('jnlR')
  126.     err = rxi_ModIDCMP(window,,,65536) /* Trap right mouse button */
  127.     do until EOF('jnlR')
  128.      gadg = gadglist
  129.      do i = 0 to numLines
  130.       gadg = rxi_ModGadg(window,gadg,,,,Entri,,,,,)
  131.       gadg = rxi_PEEK(gadg,0,2) /* Get next gadget */
  132.       Entri=readln('jnlR')
  133.      end i
  134.       if ~EOF('jnlR') then do
  135.        err = rxi_Title(window,reqdef,' Click menu button for more ',)
  136.        do while class < 3
  137.         spec = rxi_WaitMsg(window)
  138.         parse var spec class part1
  139.        end
  140.       end
  141.     end
  142.     err = rxi_Title(window,reqdef,' Journal entry for ',path)
  143.     err = rxi_ModIDCMP(window,,,4096) /* Free right mouse button */
  144.     close('jnlR')
  145.    end
  146.   else
  147.    err = rxi_Title(window,reqdef,'Cannot find ',path)
  148.  end
  149. end
  150. return('')
  151.  
  152. /* ------------ Deletes a Journal File ----------------- */
  153. DeleteEntry:
  154.  path = rxi_ReqNW(reqDef,'Delete Journal File:',8192,,'.JLE',date,,,window,-1,-1)
  155.  if path > '' then do
  156.   err = rxi_Peek(reqdef,4,0)
  157.   if err > 0 then do
  158.    /* See if the file exists, and if so, delete it. */
  159.    err = rxi_Peek(reqdef,204,2)
  160.    if err > 0 then do
  161.     err = rxi_MsgOne(window,'Delete this entry?')
  162.     if err = 1 then do
  163.      address command('delete 'path)
  164.      err = rxi_Title(window,reqdef,'Deleted ',path)
  165.     end
  166.    end
  167.   else
  168.    err = rxi_Title(window,reqdef,,)
  169.   end
  170.  end
  171.  return('')
  172.  
  173. /* ------ Clears out the text in the string gadgets ------- */
  174. NewEntry:
  175.  err = rxi_Title(window,reqdef,,)
  176.  gadg = gadglist
  177.  do i = 0 to numLines
  178.   gadg = rxi_ModGadg(window,gadg,,,,'',,,,,)
  179.   gadg = rxi_PEEK(gadg,0,2)
  180.  end i
  181.  return('')
  182.